<?php

/**
 * Created by PhpStorm
 * User Niu Yong Qiang
 * Date 2021/9/18 15:02
 */

namespace App\Models;

use Exception;

class SysPermissionsModel extends BaseModel
{
    protected $table = 'info_sys_permissions';
    public $timestamps = false;


    /**
     * 获取权限列表
     * @param $whereArr
     * @param array $columns
     * @return array
     * @throws Exception
     */
    public function getPermissionAll($whereArr, array $columns = ['*']): array
    {
        //初始化参数
        $this->queryModel = null;
        $data = [];
        if(!empty($whereArr)) {
            $this->queryModel = SysPermissionsModel::query();

            //拼接where条件sql
            $this->spliceSQL();

            $obj = $this->queryModel->select($columns)
                ->get();

            $data = $obj ? $obj->toArray() : [];
        }
        return $data;
    }

    /**
     * @param array $where
     * @param string $field
     * @param array $id
     * @return array|null
     */
    public function getDataOne(array $where=[], string $field='', array $id=[]):?array
    {
        $where[] = ['deleted_at', '=',  null];
        $res = self::query()
            ->where($where);

        if (!empty($id)){
            $res->whereIn($field, $id);
        }

        return $res->get()->toArray();
    }
}
